package design_patterns.iterator;

public class NameRepository implements MyContainer {
   public String names[] = {"Robert" , "John" ,"Julie" , "Lora"};
 
   @Override
   public Iterator getIterator() {
      return new NameIterator();
   }
 
   private class NameIterator implements Iterator {
 
      int index;

      @Override
      public boolean hasnext() {
         if(index < names.length){
            return true;
         }
         return false;
      }

      @Override
      public Object next() {
         if(this.hasnext()){
            return names[index++];
         }
         return null;
      }     
   }
}